﻿package mortal.game.view.guide.guideUse
{
    import Message.DB.Tables.*;
    import com.gengine.core.frame.*;
    import com.gengine.debug.*;
    import com.gengine.global.*;
    import com.gengine.keyBoard.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.skill.panel.render.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class GuideUseXPSkillView extends View
    {
        private var _bmpBg:GImageBitmap;
        private var _skillItem:SkillItem;
        private var _swfEffect:SWFPlayer;
        private var _txtName:GTextFiled;
        private var _box:GCheckBox;
        private var _timer:Timer;
        private var _lastTime:int = 0;
        private static var _instance:GuideUseXPSkillView;

        public function GuideUseXPSkillView()
        {
            super.layer = LayerManager.uiLayer;
            return;
        }// end function

        private function removeTimer() : void
        {
            if (this._timer != null)
            {
                this._timer.stop();
                this._timer.removeEventListener(TimerEvent.TIMER_COMPLETE, this.timerHandler);
                this._timer = null;
            }
            return;
        }// end function

        private function addTimer() : void
        {
            this._timer = new Timer(1000);
            this._timer.addEventListener(TimerEvent.TIMER, this.timerHandler);
            this._timer.start();
            return;
        }// end function

        public function updateShowTime() : void
        {
            this._lastTime = FrameManager.flashFrame.getTime();
            return;
        }// end function

        public function updateSkill(param1:int) : void
        {
            var _loc_2:* = SkillConfig.instance.getInfoById(param1);
            var _loc_3:* = new SkillInfo();
            _loc_3.tSkill = _loc_2;
            this._skillItem.skillInfo = _loc_3;
            this._txtName.text = Language.getStringByParam(21014, _loc_2.name);
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            this.x = 377;
            this.y = Global.stage.stageHeight - 237;
            this.updateShowTime();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bmpBg = UIFactory.gImageBitmap(ImagesConst.GuideUseXPBg, 0, 0, this);
            this._skillItem = UICompomentPool.getUICompoment(SkillItem) as SkillItem;
            this._skillItem.toolTipMode = SkillItem.TooltipMode_ShowNext;
            this._skillItem.setSize(60, 60);
            this._skillItem.x = 83;
            this._skillItem.y = 20;
            this._skillItem.isDragAble = true;
            this._skillItem.isShowToolTip = true;
            this.addChild(this._skillItem);
            this._swfEffect = UICompomentPool.getUICompoment(SWFPlayer);
            this._swfEffect.timeRate = 3;
            this._swfEffect.load("Guide_UseXP_bg.swf", ModelType.NormalSwf, null);
            this._swfEffect.move(this._skillItem.x + 28, this._skillItem.y + 28);
            this.addChild(this._swfEffect);
            var _loc_1:* = GlobalStyle.textFormatHuang2.center();
            _loc_1.size = 15;
            _loc_1.bold = true;
            this._txtName = UIFactory.gTextField("", 0, 81, 230, 25, this, _loc_1);
            this._txtName.filters = [FilterConst.NpcNameFilter];
            this._box = UIFactory.checkBox(Language.getString(21015), 48, 98, 147, 28, this);
            this._box.selected = ClientSetting.local.getIsDone(IsDoneType.UseWizardSkill);
            this._box.configEventListener(Event.CHANGE, this.selectedChangeHandler);
            KeyBoardManager.instance.addEventListener(KeyEvent.KEY_DOWN, this.onKeyDownHandler);
            this.configEventListener(MouseEvent.CLICK, this.useXPHandler);
            this.addTimer();
            return;
        }// end function

        private function selectedChangeHandler(param1) : void
        {
            ClientSetting.local.setIsDone(this._box.selected, IsDoneType.UseWizardSkill);
            ClientSetting.save(true);
            GameController.skill.clearAutoUseXpTimer();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bmpBg.dispose(param1);
            this._bmpBg = null;
            this._skillItem.dispose(true);
            this._skillItem = null;
            this._swfEffect.dispose(param1);
            this._swfEffect = null;
            this._box.dispose(param1);
            this._box = null;
            this._txtName.dispose(param1);
            this._txtName = null;
            KeyBoardManager.instance.removeEventListener(KeyEvent.KEY_DOWN, this.onKeyDownHandler);
            this.removeTimer();
            return;
        }// end function

        private function useXPHandler(event:MouseEvent) : void
        {
            if (event.target == this._box)
            {
                return;
            }
            Log.error("点击了指引使用XP技能的图标！");
            GameManager.instance.popupModuleType(ModuleType.XP);
            this.hide();
            return;
        }// end function

        private function onKeyDownHandler(event:KeyEvent) : void
        {
            if (event == null || event.keyData == null || event.keyData.keyMap == null)
            {
                return;
            }
            if (event.keyData.keyMap.key == ModuleType.XP)
            {
                this.hide();
            }
            return;
        }// end function

        private function timerHandler(event:TimerEvent) : void
        {
            var _loc_2:* = FrameManager.flashFrame.getTime();
            if (_loc_2 - this._lastTime >= 6000)
            {
                hide();
            }
            return;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function get instance() : GuideUseXPSkillView
        {
            if (_instance == null)
            {
                _instance = new GuideUseXPSkillView;
            }
            return _instance;
        }// end function

    }
}
